package bpm.dao.impl.document;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import bpm.domain.document.DocumentEntry;
/**
 * 
 * @author ZhaoWangLong Dec 27, 2011
 *
 */
public class DocumentEntryInsertBatchPreparedStatementSetter implements
		BatchPreparedStatementSetter {
	private List<DocumentEntry> entrys=null;
	public DocumentEntryInsertBatchPreparedStatementSetter(){}
	public DocumentEntryInsertBatchPreparedStatementSetter(List<DocumentEntry> entrys){
		this.entrys=entrys;
	}
	
	public int getBatchSize() {
		if(entrys!=null)
			return entrys.size();
		else
			return 0;
	}

	public void setValues(PreparedStatement ps, int i) throws SQLException {
		if(entrys!=null){
			ps.setString(1, entrys.get(i).getDocumentId());
			ps.setString(2, entrys.get(i).getFieldKey());
			ps.setString(3, entrys.get(i).getValue());
			if(entrys.get(i).getCreateTime()!=null)
				ps.setDate(4, new java.sql.Date(entrys.get(i).getCreateTime().getTime()));
			else
				ps.setDate(4, null);
			if(entrys.get(i).getLastUpdateTime()!=null)
				ps.setDate(5, new java.sql.Date(entrys.get(i).getLastUpdateTime().getTime()));
			else
				ps.setDate(5, null);
			ps.setString(6, entrys.get(i).getDescription());
			ps.setString(7, entrys.get(i).getId());
		}
		
	}

}
